<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属部门" prop="deptName">
        <el-select
          v-model="queryParams.deptName"
          placeholder="操作类型"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in dept"
            :key="dict.key"
            :label="dict.label"
            :value="dict.deptName"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="患者名称" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入患者名称"
          clearable
          style="width: 240px;"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="挂号类型" prop="registerName">
        <el-select
          v-model="queryParams.registerName"
          placeholder="挂号类型"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in registraLists"
            :key="dict.key"
            :label="dict.label"
            :value="dict.registerName"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号时段" prop="regisTime">
        <el-select
          v-model="queryParams.regisTime"
          placeholder="操作类型"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option label="上午" value="上午"></el-option>
          <el-option label="下午" value="下午"></el-option>
          <el-option label="晚上" value="晚上"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="挂号状态" prop="patientStatus">
        <el-select
          v-model="queryParams.patientStatus"
          placeholder="操作类型"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option label="已挂号" value="0"></el-option>
          <el-option label="待就诊" value="1"></el-option>
          <el-option label="就诊完成" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="日期选择" prop="patientTime">
        <el-date-picker
          v-model="queryParams.patientTime"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          style="width: 100%"
          placeholder="请选择日期选择"
          clearable></el-date-picker>
      </el-form-item>
      <!--<el-form-item label="操作时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['monitor:operlog:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleClean"
          v-hasPermi="['monitor:operlog:remove']"
        >清空</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['monitor:operlog:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="挂号科室" align="center" prop="dept.deptName" />
      <el-table-column label="接诊医生" align="center" prop="xlPeople.doctor" />
      <el-table-column label="挂号费用" align="center" prop="regis.registerPrice" />
      <el-table-column label="流水编号" align="center" prop="xlPeople.beforeCode" />
      <el-table-column label="状态" align="center" prop="patientStatus" width="130" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
          <span>{{ parseTimea(scope.row.patientStatus) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="就诊日期" align="center" prop="patientTime" :show-overflow-tooltip="true" />
      <el-table-column label="挂号类型" align="center" prop="regis.registerName" :show-overflow-tooltip="true" />
      <el-table-column label="挂号时段" align="center" prop="regisTime" :show-overflow-tooltip="true" />
      <!--<el-table-column label="操作状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="操作日期" align="center" prop="operTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operTime) }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding">
        <template slot-scope="scope">
          <el-button v-if="scope.row.patientStatus == 0" @click="setStatus(scope.row.patientId,0)" style="width: 50px;height: 30px"  type="success" size="mini">收费</el-button>
          <el-button v-if="scope.row.patientStatus == 0 ||scope.row.patientStatus == 1" @click="setStatus(scope.row.patientId,1)" style="width: 50px;height: 30px" type="danger" size="mini">退费</el-button>
        </template>
        <!--<template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row,scope.index)"
            v-hasPermi="['monitor:operlog:query']"
          >详细</el-button>
        </template>-->
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 操作日志详细 -->
    <el-dialog title="操作日志详细" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-col :span="12">
            <el-form-item label="操作模块：">{{ form.title }} / {{ typeFormat(form) }}</el-form-item>
            <el-form-item
              label="登录信息："
            >{{ form.operName }} / {{ form.operIp }} / {{ form.operLocation }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="请求地址：">{{ form.operUrl }}</el-form-item>
            <el-form-item label="请求方式：">{{ form.requestMethod }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="操作方法：">{{ form.method }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="请求参数：">{{ form.operParam }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="返回参数：">{{ form.jsonResult }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="操作状态：">
              <div v-if="form.status === 0">正常</div>
              <div v-else-if="form.status === 1">失败</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="操作时间：">{{ parseTime(form.operTime) }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="异常信息：" v-if="form.status === 1">{{ form.errorMsg }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPost, delOperlog, cleanOperlog, exportOperlog, listDepts, listRegistr ,registerStatus,setStatusa} from "@/api/doctor/regisList";

export default {
  name: "Operlog",
  data() {
    return {
      //sta: undefined,
      //挂号状态
      registerStatus: [],
      //挂号时段
      registerTime: [],
      //查询挂号名称
      registraLists: [],
      //查询科室下拉框内容
      dept: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 是否显示弹出层
      open: false,
      // 类型数据字典
      typeOptions: [],
      // 类型数据字典
      statusOptions: [],
      // 日期范围
      dateRange: '2021-09-28',
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
        deptName:undefined,
        registerName: undefined,
        patientName:undefined,
        regisTime: undefined,
        patientStatus: undefined,
        patientTime: undefined,
        /*operName: undefined,
        businessType: undefined,
        status: undefined*/
      }
    };
  },
  created() {
    this.getList();
    this.getDept();
    this.getRegis();
    /*this.getDicts("doctor_register_time").then(response => {
      this.registerTime = response.data;
    });
    this.getDicts("register_statusa").then(response => {
      this.registerStatus = response.data;
      //console.log("1111"+response.data[0].dictLabel)
    });*/
  },
  methods: {

    //获取全部的部门
    getDept(){
      listDepts().then(res =>{
        console.log(res)
        this.dept = res
      });
    },
    //获取所有挂号类型
    getRegis(){
      listRegistr().then(res =>{
        console.log(res)
        this.registraLists = res
      });
    },

    //收费与颓废按钮的设置
    setStatus(patientId,patientStatus){
      console.log("xiugai:"+patientId+":"+patientStatus)
      //patientStatus等于0就代表收费 等于1代表退费
      if(patientStatus == 0){
        setStatusa(patientId,patientStatus).then(response => {
          if (response>0){
            this.getList();
          }
        });
      }else if(patientStatus == 1){
        setStatusa(patientId,patientStatus).then(response => {
          if (response>0){
            this.getList();
          }
        });
      }
    },
    //将展示的状态1查询为‘正常’
    parseTimea(a){
      if (a=='0'){
        return '已挂号';
      }else if (a=='1'){
        return '待就诊';
      }else if (a=='2'){
        return '就诊完成';
      }/*else if (a=='3'){
        return '就诊完成';
      }*/
      /*registerStatus(a,"register_statusa").then(response => {
      //console.log("状态是："+response)
      this.sta = response;
  });
      return this.sta;*/
    },
    /** 查询挂号类型下拉框 */
    /*listRegistra() {
      this.loading = true;
      listRegistra().then(response => {
          this.registraLists = response;
        }
      );
    },
    /!** 查询科室下拉框 *!/
    listDepts() {
      this.loading = true;
      listDepts().then(response => {
          this.deptLists = response;
        }
      );
    },*/
    /** 查询登录日志 */
    getList() {
      this.loading = true;
      listPost(this.queryParams).then(response => {
          this.list = response.rows;
        console.log(this.list)
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 操作日志状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 操作日志类型字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.businessType);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.patientId)
      this.multiple = !selection.length
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
      this.form = row;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const operIds = row.patientId || this.ids;
      console.log(operIds)
      this.$confirm('是否确认删除日志编号为"' + operIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delOperlog(operIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      })
    },
    /** 清空按钮操作 */
    handleClean() {
      this.$confirm('是否确认清空所有操作日志数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return cleanOperlog();
      }).then(() => {
        this.getList();
        this.msgSuccess("清空成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      /*const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有操作日志数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportOperlog(queryParams);
      }).then(response => {
        this.download(response.msg);
      })*/

      this.download("/xl/regisList/export",{
        ...this.form
      },'挂号列表.xlsx')

    }
  }
};
</script>
